home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June (Extra) / CHIP 2006-06.3.iso / program / opensource / clamav-devel.exe / include / clamav.h
Encoding:
C/C++ Source or Header  |  2006-05-16  |  7.2 KB  |  250 lines

  1. /*
  2.  *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
  3.  *
  4.  *  This program is free software; you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation; either version 2 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this program; if not, write to the Free Software
  16.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17.  *  MA 02110-1301, USA.
  18.  */
  19.  
  20. #ifndef __CLAMAV_H
  21. #define __CLAMAV_H
  22.  
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <unistd.h>
  26.  
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31.  
  32.  
  33. #define CL_COUNT_PRECISION 4096
  34.  
  35. /* return codes */
  36. #define CL_CLEAN    0   /* virus not found */
  37. #define CL_VIRUS    1   /* virus found */
  38. #define CL_SUCCESS    CL_CLEAN
  39.  
  40. #define CL_EMAXREC    10  /* recursion level limit exceeded */
  41. #define CL_EMAXSIZE    11  /* size limit exceeded */
  42. #define CL_EMAXFILES    12  /* files limit exceeded */
  43. #define CL_ERAR        100 /* rar handler error */
  44. #define CL_EZIP        101 /* zip handler error */
  45. #define    CL_EMALFZIP    102 /* malformed zip */
  46. #define CL_EGZIP    103 /* gzip handler error */
  47. #define CL_EBZIP    104 /* bzip2 handler error */
  48. #define CL_EOLE2    105 /* OLE2 handler error */
  49. #define CL_EMSCOMP    106 /* compress.exe handler error */
  50. #define CL_EMSCAB    107 /* MS CAB module error */
  51. #define CL_EACCES    200 /* access denied */
  52. #define CL_ENULLARG    300 /* null argument error */
  53.  
  54. #define CL_ETMPFILE    -1  /* tmpfile() failed */
  55. #define CL_EFSYNC    -2  /* fsync() failed */
  56. #define CL_EMEM        -3  /* memory allocation error */
  57. #define CL_EOPEN    -4  /* file open error */
  58. #define CL_EMALFDB    -5  /* malformed database */
  59. #define CL_EPATSHORT    -6  /* pattern too short */
  60. #define CL_ETMPDIR    -7  /* mkdir() failed */
  61. #define CL_ECVD        -8  /* not a CVD file (or broken) */
  62. #define CL_ECVDEXTR    -9  /* CVD extraction failure */
  63. #define CL_EMD5        -10 /* MD5 verification error */
  64. #define CL_EDSIG    -11 /* digital signature verification error */
  65. #define CL_EIO        -12 /* general I/O error */
  66. #define CL_EFORMAT    -13 /* bad format or broken file */
  67.  
  68. #define CL_EHWINIT    -14 /* hardware initialization failed */
  69. #define    CL_EHWLOAD    -15 /* error loading hardware database */
  70. #define CL_EHWIO    -16 /* general hardware I/O error */
  71.  
  72.  
  73. /* db options */
  74. #define CL_DB_HWACCEL        1
  75. #define CL_DB_NOPHISHING    2
  76. #define CL_DB_ACONLY        4   /* for developers only */
  77.  
  78. /* scan options */
  79. #define CL_SCAN_RAW        0
  80. #define CL_SCAN_ARCHIVE        1
  81. #define CL_SCAN_MAIL        2
  82. #define CL_SCAN_OLE2        4
  83. #define CL_SCAN_BLOCKENCRYPTED    8
  84. #define CL_SCAN_HTML        16
  85. #define CL_SCAN_PE        32
  86. #define CL_SCAN_BLOCKBROKEN    64
  87. #define CL_SCAN_MAILURL        128
  88. #define CL_SCAN_BLOCKMAX    256
  89. #define CL_SCAN_ALGO        512
  90.  
  91. /* recommended options */
  92. #define CL_SCAN_STDOPT        (CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML | CL_SCAN_PE | CL_SCAN_ALGO) 
  93.  
  94. /* aliases for backward compatibility */
  95. #define CL_RAW        CL_SCAN_RAW
  96. #define CL_ARCHIVE    CL_SCAN_ARCHIVE
  97. #define CL_MAIL        CL_SCAN_MAIL
  98. #define CL_OLE2        CL_SCAN_OLE2
  99. #define CL_ENCRYPTED    CL_SCAN_BLOCKENCRYPTED
  100. #define cl_node        cl_engine
  101.  
  102.  
  103. struct cli_bm_patt {
  104.     char *pattern, *virname, *offset;
  105.     const char *viralias;
  106.     unsigned int length;
  107.     unsigned short target;
  108.     struct cli_bm_patt *next;
  109. };
  110.  
  111. struct cli_ac_patt {
  112.     short int *pattern;
  113.     unsigned int length, mindist, maxdist;
  114.     char *virname, *offset;
  115.     const char *viralias;
  116.     unsigned short int sigid, parts, partno, alt, *altn;
  117.     unsigned short type, target;
  118.     char **altc;
  119.     struct cli_ac_patt *next;
  120. };
  121.  
  122. struct cli_ac_node {
  123.     char islast;
  124.     struct cli_ac_patt *list;
  125.     struct cli_ac_node *trans[256], *fail;
  126. };
  127.  
  128. struct cli_md5_node {
  129.     char *virname, *viralias;
  130.     unsigned char *md5;
  131.     unsigned int size;
  132.     unsigned short fp;
  133.     struct cli_md5_node *next;
  134. };
  135.  
  136. struct cli_meta_node {
  137.     int csize, size, method;
  138.     unsigned int crc32, fileno, encrypted, maxdepth;
  139.     char *filename, *virname;
  140.     struct cli_meta_node *next;
  141. };
  142.  
  143. struct cli_matcher {
  144.     unsigned int maxpatlen; /* maximal length of pattern in db */
  145.     unsigned short ac_only;
  146.  
  147.     /* Extended Boyer-Moore */
  148.     int *bm_shift;
  149.     struct cli_bm_patt **bm_suffix;
  150.  
  151.     /* Extended Aho-Corasick */
  152.     unsigned int ac_depth;
  153.     struct cli_ac_node *ac_root, **ac_nodetable;
  154.     unsigned int ac_partsigs, ac_nodes;
  155. };
  156.  
  157. struct cl_engine {
  158.     unsigned int refcount; /* reference counter */
  159.     unsigned short hwaccel;
  160.     unsigned short sdb;
  161.  
  162.     /* Roots table */
  163.     struct cli_matcher **root;
  164.  
  165.     /* MD5 */
  166.     struct cli_md5_node **md5_hlist;
  167.  
  168.     /* Zip metadata */
  169.     struct cli_meta_node *zip_mlist;
  170.  
  171.     /* RAR metadata */
  172.     struct cli_meta_node *rar_mlist;
  173.  
  174.     /* Hardware database handle */
  175.     void *hwdb;
  176. };
  177.  
  178. struct cl_limits {
  179.     unsigned int maxreclevel; /* maximal recursion level */
  180.     unsigned int maxfiles; /* maximal number of files to be
  181.                 * scanned within an archive
  182.                 */
  183.     unsigned int maxratio; /* maximal compression ratio */
  184.     unsigned short archivememlim; /* limit memory usage for bzip2 (0/1) */
  185.     unsigned long int maxfilesize; /* files in an archive larger than
  186.                     * this limit will not be scanned
  187.                     */
  188. };
  189.  
  190. struct cl_stat {
  191.     char *dir;
  192.     int no;
  193.     struct stat *stattab;
  194.     char **statdname;
  195. };
  196.  
  197. struct cl_cvd {
  198.     char *time;        /* 2 */
  199.     int version;    /* 3 */
  200.     int sigs;        /* 4 */
  201.     short int fl;   /* 5 */
  202.     char *md5;        /* 6 */
  203.     char *dsig;        /* 7 */
  204.     char *builder;  /* 8 */
  205.     int stime;        /* 9 */
  206. };
  207.  
  208. /* file scanning */
  209. extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
  210.  
  211. extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
  212.  
  213. /* software versions */
  214. extern int cl_retflevel(void);
  215. extern const char *cl_retver(void);
  216.  
  217. /* database */
  218. extern int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *signo);
  219. extern int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo);
  220. extern int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, unsigned int options);
  221. extern const char *cl_retdbdir(void);
  222. extern struct cl_engine *cl_dup(struct cl_engine *engine);
  223.  
  224. /* CVD */
  225. extern struct cl_cvd *cl_cvdhead(const char *file);
  226. extern struct cl_cvd *cl_cvdparse(const char *head);
  227. extern int cl_cvdverify(const char *file);
  228. extern void cl_cvdfree(struct cl_cvd *cvd);
  229.  
  230. /* data dir stat functions */
  231. extern int cl_statinidir(const char *dirname, struct cl_stat *dbstat);
  232. extern int cl_statchkdir(const struct cl_stat *dbstat);
  233. extern int cl_statfree(struct cl_stat *dbstat);
  234.  
  235. /* enable debug information */
  236. extern void cl_debug(void);
  237.  
  238. extern void cl_settempdir(const char *dir, short leavetemps);
  239.  
  240. extern int cl_build(struct cl_engine *engine);
  241. extern void cl_free(struct cl_engine *engine);
  242.  
  243. extern const char *cl_strerror(int clerror);
  244.  
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248.  
  249. #endif
  250.